﻿<%@ page contentType="text/html; charset=utf-8" %>
<%@ page language="java" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" pageEncoding="utf-8"%>


<%
//驱动程序名
String driverName="com.mysql.jdbc.Driver";
//数据库用户名
String userName="root";
//密码
String userPasswd="";
//数据库名
String dbName="a0713225307";
//表名
String tableName="admin_information";
//联结字符串

request.setCharacterEncoding("UTF-8");
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd+"&useUnicode=true&characterEncoding=UTF-8";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection(url);

String sql="SELECT * FROM "+tableName+" where id = ? and Apassword = ?";

PreparedStatement pstmt = connection.prepareStatement(sql);

pstmt.setString(1, request.getParameter("id"));
pstmt.setString(2, request.getParameter("pwd"));
ResultSet rs = pstmt.executeQuery();

if (rs.next()) {
    System.out.println("yes");
	String id=rs.getString(1);
	session.setAttribute("AId",id);
	response.sendRedirect("alogin.jsp?AId='"+id+"'");
} else {
    System.out.println("no");
	response.sendRedirect("login.html");
}

rs.close();

pstmt.close();
connection.close();
%>